package com.lishe.lishe.lishe.module.me.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.lishe.lishe.R;
import com.lishe.lishe.asynchttp.LSWebHelper;
import com.lishe.lishe.lishe.base.BaseActivity;
import com.lishe.lishe.lishe.base.BaseApplication;
import com.lishe.lishe.lishe.module.auth.activity.AuthActivity;
import com.lishe.lishe.lishe.module.auth.http.AuthHttpHelper;
import com.lishe.lishe.lishe.module.excitation.activity.CompanyListActivity;
import com.lishe.lishe.lishe.utils.LoadingUtils;

import org.json.JSONObject;

/**
 * Created by zhcasecom on 2017/8/23.
 */

public class ActivitySetting extends BaseActivity implements View.OnClickListener {

    TextView title;
    Button Logout;

    private RelativeLayout phoneLayout;
    private RelativeLayout loadingKey;
    private RelativeLayout payKey;
    private RelativeLayout companyLayout;
    private TextView phone;
    private TextView comnpany;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setting);
        BaseApplication.getInstace().addActivity(ActivitySetting.this);
        init();
    }

    public static void jump(Activity activity, String phoneNum, String comName) {
        Intent intent = new Intent(activity, ActivitySetting.class);
        intent.putExtra("phoneNum", phoneNum);
        intent.putExtra("comName", comName);
        activity.startActivity(intent);
    }

    private void init() {
        phoneLayout = findViewById(R.id.phoneLayout);
        loadingKey = findViewById(R.id.loading_key);
        payKey = findViewById(R.id.pay_key);
        companyLayout = findViewById(R.id.companyLayout);
        phone = findViewById(R.id.phone);
        comnpany = findViewById(R.id.company);
        phoneLayout.setOnClickListener(this);
        loadingKey.setOnClickListener(this);
        payKey.setOnClickListener(this);
        companyLayout.setOnClickListener(this);

        phone.setText(getIntent().getStringExtra("phoneNum"));
        comnpany.setText(getIntent().getStringExtra("comName"));

        title = findViewById(R.id.title_text_title);
        title.setText("设置");

        Button back = findViewById(R.id.title_left_button);
        back.setOnClickListener(this);

        Logout = findViewById(R.id.logout);
        Logout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                LoadingUtils.createLoadingDialog(ActivitySetting.this, "请稍等...", true);
                AuthHttpHelper.doLogout(ActivitySetting.this, logoutresponse);
            }
        });
    }

    LSWebHelper.WebCallBack logoutresponse = new LSWebHelper.WebCallBack() {
        @Override
        public void onSuccess(JSONObject dataJson, String dataString, String message) {
            LoadingUtils.closeDialog();
            startActivity(new Intent(ActivitySetting.this, AuthActivity.class));
            finish();
        }

        @Override
        public void onFailure(String message) {
            LoadingUtils.closeDialog();
            Toast.makeText(ActivitySetting.this, message, Toast.LENGTH_SHORT).show();
        }
    };

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.title_left_button:
                finish();
                break;
            case R.id.phoneLayout:
                //手机号码
                break;
            case R.id.loading_key:
                //修改密码
                ActivityModifyPass.jump(this);
                break;
            case R.id.pay_key:
                //支付密码
                PayPassActivity.jump(this);
                break;
            case R.id.companyLayout:
                //切换企业
                CompanyListActivity.jump(ActivitySetting.this, 1);
                break;
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        BaseApplication.getInstace().removeActivity(ActivitySetting.this);
    }
}
